package cn.test.service;


import cn.test.dao.UserDao;
import cn.test.entity.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
* 业务层实现类
* */
@Service("loginService")
public class LoginServiceImpl implements LoginService{
    @Resource(name="userDao")
    private UserDao dao;

    public void save(User user) {
        dao.save(user);
    }

    public User findById(String id) {
        return dao.findById(id);
    }

    public void updateById(User user) {
        dao.updateById(user);
    }

    public User checkLogin(String uname, String pwd) {
        User user = dao.findByUsername(uname);
        if (user == null||!user.getUsername().equals(uname)) {
            throw new AppException("用户名错误");
        }
        if (!user.getPassword().equals(pwd)) {
            throw new AppException("密码错误");
        }
        return user;
    }

    public List<User> findbyAll() {
        return dao.findAll();
    }
}
